package com.chuangyang.fixboxmaster.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;

import com.chuangyang.fixboxlib.utils.StringUtils;
import com.chuangyang.fixboxmaster.R;
import com.chuangyang.fixboxmaster.utils.Constants;

/**
 * Created by vanshu on 15/11/26 17:44.
 */
public class RegistrationActivity extends BaseActivity {
    private EditText mUserName;
    private EditText mPhoneNumber;
    private EditText mIdCard;
    private EditText mIdCardAddress;
    private EditText mAddress;
    private EditText mBank;
    private EditText mBankNo;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("注册");
        setContentView(R.layout.activity_reistry);
        mUserName = (EditText) findViewById(R.id.et_user_name);
        mPhoneNumber = (EditText) findViewById(R.id.et_phone_number);
        mIdCard = (EditText) findViewById(R.id.et_id_card);
        mIdCardAddress = (EditText) findViewById(R.id.et_id_card_address);
        mAddress = (EditText) findViewById(R.id.et_address);
        mBank = (EditText) findViewById(R.id.et_bank);
        mBankNo = (EditText) findViewById(R.id.et_bank_no);
    }


    public boolean validate() {
        if (mUserName.getText().toString().isEmpty()) {
            mUserName.setError("请输入真实姓名");
            return false;
        } else if (mPhoneNumber.getText().toString().isEmpty()) {
            mPhoneNumber.setError("请输入手机号");
            return false;
        }else if (mPhoneNumber.getText().toString().length()!=11) {
            mPhoneNumber.setError("请输入正确的手机号");
            return false;
        }else if(mIdCard.getText().toString().isEmpty()) {
            mIdCard.setError("请输入身份证号码");
            return false;
        }else if(mIdCard.getText().toString().length()!=15||mIdCard.getText().toString().length()!=18){
            mIdCard.setError("请输入正确身份证号码");
            return false;
        }else if(mIdCardAddress.getText().toString().isEmpty()) {
            mIdCardAddress.setError("请输入户籍地址");
            return false;
        }else if(mAddress.getText().toString().isEmpty()) {
            mAddress.setError("请输入现在居住地地址");
            return false;
        }else if(mBank.getText().toString().isEmpty()) {
            mBank.setError("请输入开户行");
            return false;
        }else if(mBankNo.getText().toString().isEmpty()) {
            mBankNo.setError("请输入银行卡号");
            return false;
        }
        return true;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.contact_registry_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_contact_phone_number:
                StringUtils.dialPhone(this, Constants.COSTOM_SERVICE_NUMBER);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
